home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Moscow ML 1.42 / examples / cgi / README2 < prev    next >
Encoding:
Text File  |  1997-08-18  |  2.5 KB  |  67 lines  |  [TEXT/R*ch]

  1. Example 2: Form-based file upload in HTML
  2. -----------------------------------------
  3.  
  4. To upload a file from the client (browser) to a WWW server, you need
  5. to write the following components:
  6.  
  7.         (A) An HTML page containing a FORM
  8.         (B) A CGI program to receive the file, process it, and respond
  9.   
  10. (A) You need an HTML page containing a FORM.  The FORM must have
  11.  
  12.         - METHOD="POST" and ENCTYPE="multipart/form-data"  
  13.         - an ACTION equalling the URL of a CGI program
  14.         - an INPUT field of TYPE=FILE
  15.         - one or more INPUT fields with TYPE=SUBMIT
  16.         - optionally other fields (INPUT, SELECT, ...)
  17.  
  18. See file `upload.html' for an example HTML form.  With that form, you
  19. can select a local file (on the system running the browser) and choose
  20. whether you want to count the number of characters in the file, count
  21. the number of lines in the file, or sort the file.
  22.  
  23. Note that with upload.html, the chosen file is transmitted as a part
  24. called "filecontents", and the selected menu option is transmitted as
  25. another part called "action".
  26.  
  27.  
  28. (B) You need a CGI program
  29.  
  30. See file `cgiex2.sml' for an example CGI program.  That program will
  31. handle requests sent from the above-mentioned example form.  Within
  32. the example CGI program, the contents of the uploaded file is
  33. retrieved as
  34.         Mosmlcgi.part_data (valOf (Mosmlcgi.cgi_part "filecontents"))
  35. and the chosen select menu option is retrieved as
  36.         Mosmlcgi.part_data (valOf (Mosmlcgi.cgi_part "action"))
  37. Morover, the name of the uploaded file can usually be retrieved as
  38.         Mosmlcgi.part_field_string (valOf (Mosmlcgi.cgi_part "filecontents")) 
  39.                                    "filename"
  40.  
  41.  
  42. INSTRUCTIONS FOR USE
  43.  
  44. (1) Edit the FORM in file `upload.html' so that ACTION refers to a
  45. cgi-bin directory on your local webserver.
  46.  
  47. (2) Compile the CGI program:
  48.  
  49.    mosmlc -c cgiex2.sml
  50.    mosmlc -o cgiex2 cgiex2.uo
  51.  
  52. (3) Install the compiled CGI program on your local webserver:
  53.  
  54.    cat `which camlrunm` cgiex2 > /var/lib/httpd/cgi-bin/sestoft/cgiex2
  55.    chmod a+x /var/lib/httpd/cgi-bin/sestoft/cgiex2
  56.  
  57. The above assumes that your webserver lives in /var/lib/httpd/ so that
  58. your CGI program directory is /var/lib/httpd/cgi-bin/sestoft/, and
  59. that you are allowed to install CGI programs on your webserver.
  60. Change the path as appropriate.  (Note that the runtime system is
  61. simply prepended to the ML bytecode, so that the webserver need not
  62. look for it.)
  63.  
  64. The included Makefile automates steps (2) and (3) above.
  65.  
  66. (4) Open the HTML file `upload.html' with your webbrowser, select a file and an action, and click on `Send'.
  67.